<template>
  <div class="login">
    <!-- 盒子包裹 -->
    <div class="box">
      <!-- 图片 -->
      <div class="img-box">
        <img src="../../assets/images/办公.png" alt="">
      </div>
      <!-- 表单 -->
      <div class="form-box">
        <h1>登录</h1>
        <!-- <input class="item" type="text" placeholder="请输入用户名">
        <input class="item" type="password" placeholder="请输入密码" style="margin-top: 30px;"> -->
        <el-input v-model="userForm.username" class="input-border-style" placeholder="请输入用户名"  />
        <el-input v-model="userForm.password" type="password" placeholder="请输入密码" show-password />
        <button class="btn" @click="onLogin()">登录</button>
      </div>
    </div>
  </div>
</template>
<script setup>
import router from '@/router'
import { useUserStore } from '@/stores/user';
import { ref } from 'vue'

// 实例化仓库
const userStore = useUserStore()

// 用户信息
const userForm = ref({
  username: 'admin',
  password: '123456'
})
// 点击了登录
async function onLogin() {
  if (!userForm.value.username.trim('')) {
    ElMessage.warning('请输入用户名')
    return
  }
  if (!userForm.value.password.trim('')) {
    ElMessage.warning('请输入密码')
    return
  }
  // 调用仓库中的登录方法
  await userStore.getUserInfo({
    username: userForm.value.username,
    password: userForm.value.password
  })
  // 提示登录成功
  ElMessage({ type: 'success', message: '登录成功' })
  // 跳转到首页
  router.replace('/')
}
</script>

<style lang="scss" scoped>
.login {
  background: linear-gradient(135deg, #292a3a, #536976);
  width: 100vw;
  height: 100vh;
  margin: 0;

  .box {
    width: 49%;
    height: 380px;
    box-shadow: 0 5px 15px rgba(0, 0, 0);
    display: flex;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 10px;

    .img-box {
      border-radius: 10px 6px 0px 0;
      width: 60%;
      overflow: hidden;
      background-color: transparent;

      img {
        opacity: 0.6;
        border-radius: 10px 0 6px 10px;
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }

    .form-box {
      border-radius: 0px 10px 10px 0px;
      width: 40%;
      height: 100%;
      background-color: transparent;
      padding: 0 20px;

      h1 {
        text-align: center;
        padding-top: 40px;
        color: #39a8db;
        font-weight: bold;
      }

      .el-input {
        
        margin-top: 20px;
        margin-left: 8px;
        height: 44px;
        padding: 0;
        // padding-left: 5px;
        // background: none;
        // border: none;
        // outline: none;
        border-bottom: 3px solid #8597b4;
        font-size: 13px;
        width: 260px;

        &::placeholder {
          font-size: 13px;
        }

      }

      .btn {
        background: linear-gradient(135deg, #8597b4, #aac9fa);
        color: #757575;
        font-weight: bold;
        height: 35px;
        width: 280px;
        font-size: 15px;
        border: 1px solid #aac9fa;
        border-radius: 10px;
        display: block;
        margin: auto;
        margin-top: 30px;
        cursor: pointer;
      }

      .btn:hover {
        border: 2px solid #aac9fa;
        color: #39a8db;
      }
    }
  }
}
</style>